﻿using System;
using System.Text;


namespace GoShopping.Utility //可以修改成实际项目的命名空间名称
{
    /// <summary>
    /// 显示消息提示对话框。
    /// 李天平
    /// 2005.10.1
    /// </summary>
    public class MessageBox
    {
        private MessageBox()
        {
        }

        /// <summary>
        /// 显示消息提示对话框
        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="msg">提示信息</param>
        public static void Show(System.Web.UI.Page page, string msg)
        {
            page.RegisterStartupScript("message", "<script language='javascript' defer>alert('" + msg.ToString() + "');</script>");
        }

        /// <summary>
        /// 控件点击 消息确认提示框
        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="msg">提示信息</param>
        public static void ShowConfirm(System.Web.UI.WebControls.WebControl Control, string msg)
        {
            //Control.Attributes.Add("onClick","if (!window.confirm('"+msg+"')){return false;}");
            Control.Attributes.Add("onclick", "return confirm('" + msg + "');");
        }

        /// <summary>
        /// 显示消息提示对话框，并进行页面跳转
        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="msg">提示信息</param>
        /// <param name="url">跳转的目标URL</param>
        public static void ShowAndRedirect(System.Web.UI.Page page, string msg, string url)
        {
            StringBuilder Builder = new StringBuilder();
            Builder.Append("<script language='javascript' defer>");
            Builder.AppendFormat("alert('{0}');", msg);
            Builder.AppendFormat("top.location.href='{0}'", url);
            Builder.Append("</script>");
            page.RegisterStartupScript("message", Builder.ToString());

        }
        /// <summary>
        /// 输出自定义脚本信息
        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="script">输出脚本</param>
        public static void ResponseScript(System.Web.UI.Page page, string script)
        {
            page.RegisterStartupScript("message", "<script language='javascript' defer>" + script + "</script>");
        }


        /// <summary>
        /// 网页上弹出类似MSN形式的消息框
        /// 程序集EeekSoft.Web.PopupWin
        /// </summary>
        /// <param name="PopupWin1">PopupWin</param>
        /// <param name="Message">要显示的消息</param>
        /// <param name="Caption">标题,如果赋string.Empty则默认为“提示”</param>
        public static void ShowPopupWinMsg(EeekSoft.Web.PopupWin PopupWin1, string Message, string Caption)
        {
            //设置为默认的消息窗口 
            PopupWin1.ActionType = EeekSoft.Web.PopupAction.MessageWindow;
            //设置窗口的标题，消息文字 
            string s_Caption = "提示";
            if (!string.IsNullOrEmpty(Caption))
            {
                s_Caption = Caption;
            }
            PopupWin1.Title = s_Caption;
            PopupWin1.Message = Message;
            PopupWin1.Text = Message;
            //设置颜色风格 
            PopupWin1.ColorStyle = EeekSoft.Web.PopupColorStyle.Blue;
            //设置窗口弹出和消失的时间 
            PopupWin1.HideAfter = 3000;
            PopupWin1.ShowAfter = 100;
            PopupWin1.Visible = true;
        }

    }
}

